home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / RCS / Ulog_LastLogin.c,v < prev    next >
Encoding:
Text File  |  1988-09-23  |  4.0 KB  |  211 lines

  1. head     1.4;
  2. access   ;
  3. symbols  ;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 1.4
  9. date     88.09.22.22.14.13;  author douglis;  state Exp;
  10. branches ;
  11. next     1.3;
  12.  
  13. 1.3
  14. date     88.09.15.10.16.58;  author douglis;  state Exp;
  15. branches ;
  16. next     1.2;
  17.  
  18. 1.2
  19. date     88.09.13.16.44.15;  author douglis;  state Exp;
  20. branches ;
  21. next     1.1;
  22.  
  23. 1.1
  24. date     88.08.14.15.11.51;  author douglis;  state Exp;
  25. branches ;
  26. next     ;
  27.  
  28.  
  29. desc
  30. @Get the last time someone logged in, from the login database.
  31. @
  32.  
  33.  
  34. 1.4
  35. log
  36. @return ptr to static buffer
  37. @
  38. text
  39. @/* 
  40.  * Ulog_LastLogin.c --
  41.  *
  42.  *    Source code for the Ulog_LastLogin procedure.
  43.  *
  44.  * Copyright 1988 Regents of the University of California
  45.  * Permission to use, copy, modify, and distribute this
  46.  * software and its documentation for any purpose and without
  47.  * fee is hereby granted, provided that the above copyright
  48.  * notice appear in all copies.  The University of California
  49.  * makes no representations about the suitability of this
  50.  * software for any purpose.  It is provided "as is" without
  51.  * express or implied warranty.
  52.  */
  53.  
  54. #ifndef lint
  55. static char rcsid[] = "$Header: Ulog_LastLogin.c,v 1.3 88/09/15 10:16:58 douglis Exp $ SPRITE (Berkeley)";
  56. #endif not lint
  57.  
  58.  
  59. #include <ulog.h>
  60. #include "ulogInt.h"
  61.  
  62.  
  63. /*
  64.  *----------------------------------------------------------------------
  65.  *
  66.  * Ulog_LastLogin --
  67.  *
  68.  *    Retrieve information for the last login of the specified user.
  69.  *
  70.  * Results:
  71.  *    The user log data structure is returned if the retrieval is
  72.  *    successful.  If there is no valid entry for the specified user,
  73.  *    or if an error occurs accessing the 'last log', NULL is returned.
  74.  *
  75.  * Side effects:
  76.  *    The 'last log' is opened, locked, and read before closing it again.
  77.  *
  78.  *----------------------------------------------------------------------
  79.  */
  80.  
  81.  
  82. Ulog_Data *
  83. Ulog_LastLogin(uid)
  84.     int uid;
  85. {
  86.     static Ulog_Data data;
  87.     char buffer[ULOG_RECORD_LENGTH];
  88.     int status;
  89.     int count;
  90.     
  91.     status = Db_ReadEntry(LASTLOG_FILE_NAME, buffer, uid, ULOG_RECORD_LENGTH,
  92.                DB_LOCK_BREAK);
  93.     if (status != 0) {
  94.     return((Ulog_Data *) NULL);
  95.     }
  96.     if (buffer[0] == '\0') {
  97.     errno = EACCES;
  98.     return((Ulog_Data *) NULL);
  99.     }
  100.     /*
  101.      * Try to parse the record.  It's okay if the location field
  102.      * doesn't match because it may be empty.
  103.      */
  104.     count = sscanf(buffer, ULOG_FORMAT_STRING, &data.uid,
  105.            &data.hostID, &data.portID,
  106.            &data.updated, data.location);
  107.     if (count < ULOG_ITEM_COUNT - 1) {
  108.     syslog(LOG_ERR, "Ulog_LastLogin: unable to parse record %d",
  109.            uid);
  110.     errno = EACCES;
  111.     return((Ulog_Data *) NULL);
  112.     } else if (count == ULOG_ITEM_COUNT - 1) {
  113.     data.location[0] = '\0';
  114.     }
  115.     return(&data);
  116. }
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. @
  125.  
  126.  
  127. 1.3
  128. log
  129. @allow an empty location field (since it's last in the record, this is
  130. okay).
  131. @
  132. text
  133. @d17 1
  134. a17 1
  135. static char rcsid[] = "$Header: Ulog_LastLogin.c,v 1.2 88/09/13 16:44:15 douglis Exp $ SPRITE (Berkeley)";
  136. d33 3
  137. a35 2
  138.  *    -1 indicates an error, in which case errno indicates more details.
  139.  *    0 indicates success.
  140. d43 3
  141. a45 2
  142. int
  143. Ulog_LastLogin(uid, dataPtr)
  144. a46 1
  145.     Ulog_Data *dataPtr;
  146. d48 1
  147. d53 2
  148. a54 2
  149.     status = Db_ReadEntry(LASTLOG_FILE_NAME, uid, ULOG_RECORD_LENGTH,
  150.                buffer, DB_LOCK_BREAK);
  151. d56 1
  152. a56 1
  153.     return(-1);
  154. d60 1
  155. a60 1
  156.     return(-1);
  157. d66 3
  158. a68 3
  159.     count = sscanf(buffer, ULOG_FORMAT_STRING, &dataPtr->uid,
  160.            &dataPtr->hostID, &dataPtr->portID,
  161.            &dataPtr->updated, dataPtr->location);
  162. d73 1
  163. a73 1
  164.     return(-1);
  165. d75 1
  166. a75 1
  167.     dataPtr->location[0] = '\0';
  168. d77 1
  169. a77 1
  170.     return(0);
  171. d79 4
  172. @
  173.  
  174.  
  175. 1.2
  176. log
  177. @changed to use ascii representation in database file.
  178. @
  179. text
  180. @d17 1
  181. a17 1
  182. static char rcsid[] = "$Header: Ulog_LastLogin.c,v 1.1 88/08/14 15:11:51 douglis Exp $ SPRITE (Berkeley)";
  183. d54 1
  184. a54 1
  185.     return(status);
  186. d56 8
  187. d67 1
  188. a67 1
  189.     if (count != ULOG_ITEM_COUNT) {
  190. d72 2
  191. d77 3
  192. @
  193.  
  194.  
  195. 1.1
  196. log
  197. @Initial revision
  198. @
  199. text
  200. @d17 1
  201. a17 1
  202. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  203. d47 1
  204. d49 1
  205. d51 15
  206. a65 3
  207.     status = Db_ReadEntry(LASTLOG_FILE_NAME, uid, sizeof(Ulog_Data),
  208.                (char *) dataPtr, DB_LOCK_BREAK);
  209.     return(status);
  210. @
  211.